import { RangePicker } from 'ant-design-vue';
import { BasicColumn, FormSchema } from '/@/components/Table';
import { h } from 'vue';
import { listByCommunity } from './cellAddress.api';

export const columns: BasicColumn[] = [
  {
    title: '省',
    dataIndex: 'province',
    width: 80,
  },
  {
    title: '市',
    dataIndex: 'city',
    width: 100,
  },
  {
    title: '区',
    dataIndex: 'district',
    width: 150,
  },
  {
    title: '地址概述',
    dataIndex: 'title',
    width: 90,
  },
  {
    title: '小区地址',
    dataIndex: 'address',
    width: 90,
  },
  {
    title: '经度',
    dataIndex: 'longitude',
    width: 90,
  },
  {
    title: '纬度',
    dataIndex: 'latitude',
    width: 90,
  },
  {
    title: '所属社区',
    dataIndex: 'communityId',
    width: 90,
  },
  {
    title: '是否为社区',
    dataIndex: 'isCommunity',
    width: 90,
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'isCommunity',
    label: '是否为社区',
    component: 'RadioGroup',
    componentProps: {
      //options里面由一个一个的radio组成,支持disabled
      options: [
        { label: '是', value: 1 },
        { label: '否', value: 0 },
      ],
    },
  },
  {
    label: '所属社区',
    field: 'status',
    component: 'JSelectInput',
    componentProps: {
      api: listByCommunity,
      resultField: 'result',
      labelField: 'address',
      valueField: 'id',
    },
  },
];

export const formSchemas: FormSchema[] = [
  {
    label: 'ID',
    field: 'id',
    component: 'Input',
    show: false,
  },
  {
    label: 'province',
    field: 'province',
    component: 'Input',
    show: false,
  },
  {
    label: 'city',
    field: 'city',
    component: 'Input',
    show: false,
  },
  {
    label: 'district',
    field: 'district',
    component: 'Input',
    show: false,
  },
  {
    label: '省市区',
    field: 'pcaSelect',
    component: 'JAreaSelect',
    componentProps: {
      //级别 1 只显示省 2 省市 3 省市区
      level: 3,
    },
    slot: 'pcaSelect',
  },
  {
    label: '地址概述',
    field: 'title',
    component: 'Input',
  },
  {
    label: '小区地址',
    field: 'address',
    component: 'Input',
    slot: 'baiduMaps',
  },
  {
    label: '经度',
    field: 'longitude',
    component: 'Input',
    dynamicDisabled: true,
  },
  {
    label: '纬度',
    field: 'latitude',
    component: 'Input',
    dynamicDisabled: true,
  },
  {
    label: '所属社区',
    field: 'addressId_dictText',
    component: 'ApiSelect',
    componentProps: {
      api: listByCommunity,
      resultField: 'result',
      labelField: 'address',
      valueField: 'id',
    },
    //动态禁用，values代表当前表单的值，返回 true或false
    dynamicDisabled: ({ values }) => {
      return values.isCommunity == 1;
    },
  },
  {
    label: '是否社区',
    field: 'isCommunity',
    component: 'Select',
    componentProps: {
      options: [
        { value: 1, label: '是' },
        { value: 0, label: '否' },
      ],
    },
    //自动触发检验，布尔类型
    required: true,
  },
];
